$(document).ready(function () {
  banner();
  newsBanner();
  autoScroll();
  
  
  function autoScroll() {
    var activeIndex = 0;
    $('.notice .new-list-box i').click(function () {
      if ($('.notice .new-list-box .content-box p').length < 2) {
        return
      }
      var num = 1;
      if ($(this).index() < 1) {
        num = -1;
      }
      move(num);
    });
    if ($('.notice .new-list-box .content-box p').length > 1) {
      autoPlay();
    }
    function autoPlay() {
      setTimeout(function () {
        move(1);
        autoPlay();
      }, 3000)
    }
    function move(num) {
      var nowIndex = activeIndex;
      var eleHeight = $('.notice .new-list-box .content-box p').height();
      activeIndex += num;
      if (activeIndex < 0) {
        activeIndex = $('.notice .new-list-box .content-box p').length - 1;
      }
      if (activeIndex > $('.notice .new-list-box .content-box p').length - 1) {
        activeIndex = 0;
      }
      $('.notice .new-list-box .content-box p').eq(nowIndex).animate({
        top: -num * eleHeight + 'px'
      }, function () {
        $('.notice .new-list-box .content-box p').eq(nowIndex).addClass('active').siblings().removeClass('active');
      });
      
      $('.notice .new-list-box .content-box p').eq(activeIndex).css({top: num * eleHeight + 'px'});
      $('.notice .new-list-box .content-box p').eq(activeIndex).animate({
        top: 0
      }, function () {
        $('.notice .new-list-box .content-box p').eq(activeIndex);
      })
    }
  }
  
  
  function newsBanner() {
    var activeIndex = 0;
    $('.news-banner .angle-box i').eq(0).click(function () {
      angleClick(-1);
    });
    $('.news-banner .angle-box i').eq(1).click(function () {
      angleClick(1);
    });
    $('.news-banner .point-box span').hover(function () {
      activeIndex = $(this).index();
      setActive(activeIndex);
    });
    autoPlay();
    function angleClick(num) {
      activeIndex += num;
      if (activeIndex > $('.news-banner .img-box').length - 1) {
        activeIndex = 0;
      }
      if (activeIndex < 0) {
        activeIndex = $('.news-banner .img-box').length - 1;
      }
      setActive(activeIndex);
    }
    function setActive(index) {
      $('.news-banner .img-box').eq(index).addClass('active').siblings().removeClass('active');
      $('.news-banner .point-box span').eq(index).addClass('active').siblings().removeClass('active');
    }
    function autoPlay() {
      setTimeout(function () {
        angleClick(1);
        autoPlay();
      }, 5000)
    }
  }
  
  
  
  
  function banner() {
    var activeIndex = 0;
    $('.banner .angle-box i').eq(0).click(function () {
      angleClick(-1);
    });
    $('.banner .angle-box i').eq(1).click(function () {
      angleClick(1);
    });
    $('.point-box span').click(function () {
      activeIndex = $(this).index();
      setActive(activeIndex);
    });
    autoPlay();
    function angleClick(num) {
      activeIndex += num;
      if (activeIndex > $('.banner .img-box').length - 1) {
        activeIndex = 0;
      }
      if (activeIndex < 0) {
        activeIndex = $('.banner .img-box').length - 1;
      }
      setActive(activeIndex);
    }
    function setActive(index) {
      $('.banner .img-box').eq(index).addClass('active').siblings().removeClass('active');
      $('.point-box span').eq(index).addClass('active').siblings().removeClass('active');
    }
    function autoPlay() {
      setTimeout(function () {
        angleClick(1);
        autoPlay();
      }, 3000)
    }
  }
});